package com.duniptech.soa.service;

import com.duniptech.soa.stub.simulation.SimulationStub;



public class SimulationService implements SimulationServiceInterface {
	protected SimulationStub service;
		
	public SimulationService(String endPoint) throws Exception {
		service = new SimulationStub(endPoint);
	}
	
	public String simulate(String clientIp, String serverPackage, String xmlModelAsString, long numIterations) throws Exception {
		SimulationStub.Simulate args = new SimulationStub.Simulate();
		args.setClientIp(clientIp);
		args.setServerPackage(serverPackage);
		args.setXmlModelAsString(xmlModelAsString);
		args.setNumIterations(numIterations);
		
		SimulationStub.SimulateResponse response = service.simulate(args);
		return response.get_return();
	}
	
	public void newSimulator(String xmlAtomicAsString) throws Exception {
		SimulationStub.NewSimulator args = new SimulationStub.NewSimulator();
		args.setXmlAtomicAsString(xmlAtomicAsString);
		
		service.newSimulator(args);
	}
	
	public void initialize(String key, double t) throws Exception {
		SimulationStub.Initialize args = new SimulationStub.Initialize();
		args.setKey(key);
		args.setT(t);
		
		service.initialize(args);
	}
	
	public double getTN(String key) throws Exception {
		SimulationStub.GetTN args = new SimulationStub.GetTN();
		args.setKey(key);
		
		SimulationStub.GetTNResponse response = service.getTN(args);
		return response.get_return();
	}
	
	public void lambda(String key, double t) throws Exception {
		SimulationStub.Lambda args = new SimulationStub.Lambda();
		args.setKey(key);
		args.setT(t);
		
		service.lambda(args);
	}
	
	public String[] getOutput(String key, String portName) throws Exception {
		SimulationStub.GetOutput args = new SimulationStub.GetOutput();
		args.setKey(key);
		args.setPortName(portName);
		
		SimulationStub.GetOutputResponse response = service.getOutput(args);
		return response.get_return();
	}
	
	public void receive(String key, String simulatorFrom, String portFrom, String simulatorTo, String portTo, String[] xmlValues) throws Exception {
		SimulationStub.Receive args = new SimulationStub.Receive();
		args.setKey(key);
		args.setSimulatorFrom(simulatorFrom);
		args.setPortFrom(portFrom);
		args.setSimulatorTo(simulatorTo);
		args.setPortTo(portTo);
		args.setXmlValues(xmlValues);
		
		service.receive(args);
	}
	
	public void deltfcn(String key, double t) throws Exception {
		SimulationStub.Deltfcn args = new SimulationStub.Deltfcn();
		args.setKey(key);
		args.setT(t);
		
		service.deltfcn(args);
	}
	
	public String getConsole(String clientIp) throws Exception {
		SimulationStub.GetConsole args = new SimulationStub.GetConsole();
		args.setClientIp(clientIp);
		
		SimulationStub.GetConsoleResponse response = service.getConsole(args);
		return response.get_return();
	}
	
	public void exit(String key) throws Exception {
		SimulationStub.Exit args = new SimulationStub.Exit();
		args.setKey(key);
		
		service.exit(args);
	}
	
}
